package com.ruoyi.cms.service.impl;

import com.ruoyi.cms.domain.ShortVideo;
import com.ruoyi.cms.mapper.ShortVideoMapper;
import com.ruoyi.cms.service.IShortVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * 短视频Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-22
 */
@Service
public class ShortVideoServiceImpl implements IShortVideoService {

    @Autowired
    private ShortVideoMapper shortVideoMapper;

    /**
     * 查询短视频
     *
     * @param videoId 短视频主键
     * @return 短视频
     */
    @Override
    public ShortVideo selectShortVideoById(Long videoId) {
        return shortVideoMapper.selectShortVideoById(videoId);
    }

    /**
     * 查询短视频列表
     *
     * @param shortVideo 短视频
     * @return 短视频集合
     */
    @Override
    public List<ShortVideo> selectShortVideoList(ShortVideo shortVideo) {
        return shortVideoMapper.selectShortVideoList(shortVideo);
    }

    /**
     * 新增短视频
     *
     * @param shortVideo 短视频
     * @return 结果
     */
    @Override
    public int insertShortVideo(ShortVideo shortVideo) {
        shortVideo.setCreateTime(new Date());
        return shortVideoMapper.insertShortVideo(shortVideo);
    }

    /**
     * 修改短视频
     *
     * @param shortVideo 短视频
     * @return 结果
     */
    @Override
    public int updateShortVideo(ShortVideo shortVideo) {
        shortVideo.setUpdateTime(new Date());
        return shortVideoMapper.updateShortVideo(shortVideo);
    }

    /**
     * 批量删除短视频
     *
     * @param videoIds 需要删除的短视频主键集合
     * @return 结果
     */
    @Override
    public int deleteShortVideoByIds(Long[] videoIds) {
        return shortVideoMapper.deleteShortVideoByIds(videoIds);
    }

    /**
     * 删除短视频信息
     *
     * @param videoId 短视频主键
     * @return 结果
     */
    @Override
    public int deleteShortVideoById(Long videoId) {
        return shortVideoMapper.deleteShortVideoById(videoId);
    }

    /**
     * 审核短视频
     *
     * @param shortVideo 短视频（包含审核状态和意见）
     * @return 结果
     */
    @Override
    public int auditShortVideo(ShortVideo shortVideo) {
        // TODO: Audit functionality removed in new design
        return shortVideoMapper.updateShortVideo(shortVideo);
    }

    /**
     * 增加播放量
     *
     * @param videoId 短视频ID
     * @return 结果
     */
    @Override
    public int increaseViewCount(Long videoId) {
        return shortVideoMapper.increaseViewCount(videoId);
    }

    /**
     * 增加点赞量
     *
     * @param videoId 短视频ID
     * @return 结果
     */
    @Override
    public int increaseLikeCount(Long videoId) {
        return shortVideoMapper.increaseLikeCount(videoId);
    }

    /**
     * 批量审核通过
     *
     * @param videoIds 短视频ID数组
     * @return 结果
     */
    @Override
    public int approveVideos(Long[] videoIds) {
        int result = 0;
        for (Long videoId : videoIds) {
            ShortVideo video = new ShortVideo();
            video.setShortId(videoId.intValue());
            // TODO: Audit functionality removed in new design
            result += shortVideoMapper.updateShortVideo(video);
        }
        return result;
    }

    /**
     * 批量审核拒绝
     *
     * @param videoIds 短视频ID数组
     * @return 结果
     */
    @Override
    public int rejectVideos(Long[] videoIds) {
        int result = 0;
        for (Long videoId : videoIds) {
            ShortVideo video = new ShortVideo();
            video.setShortId(videoId.intValue());
            // TODO: Audit functionality removed in new design
            result += shortVideoMapper.updateShortVideo(video);
        }
        return result;
    }

    /**
     * 查询已审核通过��短视频列表
     *
     * @return 短视频列表
     */
    @Override
    public List<ShortVideo> selectApprovedVideos() {
        ShortVideo shortVideo = new ShortVideo();
        // TODO: Audit functionality removed in new design - returning all videos with status=0
        shortVideo.setStatus("0");
        return shortVideoMapper.selectShortVideoList(shortVideo);
    }

    /**
     * 查询热门短视频列表
     *
     * @param limit 返回数量限制
     * @return 短视频列表
     */
    @Override
    public List<ShortVideo> selectHotVideos(Integer limit) {
        return shortVideoMapper.selectHotVideos(limit);
    }
}